<template>
  <FrontSideTable
    dataUrl="/sys/mobileVersion/getList"
    addUrl="/sys/mobileVersion/add"
    editUrl="/sys/mobileVersion/edit"
    deleteUrl="/sys/mobileVersion/delete"
    tableTitle="移动端版本列表"
    searchHint="根据移动端版本号查找"
    :searchProps="searchProps"
    :columns="columns"
    :form="form"
    :rules="rules"
    @beforeAdd="beforeAdd"
    @beforeEdit="beforeEdit"
    @onCreated="onCreated">
    <template slot="beforeColumns">
      <el-table-column type="expand">
        <template slot-scope="scope">
          <File
            :fileData="scope.row"
            uploadUrl="/sys/mobileVersion/uploadInstallFile"
            downloadUrl="/sys/mobileVersion/downloadInstallFile"
            :uploadParam="scope.row"
            deleteUrl="/sys/mobileVersion/deleteInstallFile"
            @onSuccess="file=>scope.row.path = file.path"
            @onRemove="()=>scope.row.path = ''">
          </File>
        </template>
      </el-table-column>
    </template>
    <template slot="form">
      <el-form-item label="版本号" prop="versionCode">
        <el-input type="number" v-model.number="form.versionCode" placeholder="输入版本号"></el-input>
      </el-form-item>
      <el-form-item label="版本描述" prop="versionDesc">
        <el-input type="textarea" v-model="form.versionDesc"></el-input>
      </el-form-item>
    </template>
  </FrontSideTable>
</template>

<script>
  import FrontSideTable from "../../template/FrontSideTable.vue"
  import File from "../../template/File.vue"
  import {clearFields} from "../../../assets/js/utils/ObjectUtils";
  import {intValidator} from "../../../assets/js/utils/ValidateUtils";

  //用于编辑时版本号重复校验
  let oldVersionCode = "";

  export default {
    name:"MobileVersionManagement",
    data() {
      let versionCodeValidator = (rule, value, callback) => {
        if(oldVersionCode === value) {
          callback();
        } else {
          if(this.dataList.some(item=>item.versionCode === value)) {
            callback(new Error("版本号重复"))
          } else {
            callback();
          }
        }
      };

      return {
        dataList:[],
        searchProps:["versionCode", "versionDesc"],
        columns:[
          {prop:"versionCode", label:"版本号", width:"120"},
          {prop:"versionDesc", label:"版本描述"},
          {prop:"createDate", label:"发布日期", width:"120"}
        ],
        form:{
          versionCode:"",
          versionDesc:""
        },
        rules:{
          versionCode: [
            {required:true, type:"number", message:"请输入版本号", trigger:"blur"},
            {validator:versionCodeValidator, trigger:"blur"},
            {validator:intValidator, trigger:"blur"}
          ],
          versionDesc: [
            {required:true, message:"请输入版本描述", trigger:"blur"}
          ]
        }
      }
    },
    methods: {
      onCreated(dataList) {
        this.dataList = dataList;
      },
      beforeAdd() {
        oldVersionCode = "";
        clearFields(this.form);
      },
      beforeEdit(data) {
        oldVersionCode = data.versionCode;
        this.form = {...data};
      }
    },
    components:{FrontSideTable, File}
  }
</script>



// WEBPACK FOOTER //
// MobileVersionManagement.vue?6e9c26ef
